# coding:utf-8


# Class Category def
class Category:
    cat_id = None
    cat_name = None
    cat_url = None
    father = None
    has_child = None
    updated = None

    def __init__(self, cat_id, cat_name, url, updated=None):
        self.cat_id = cat_id
        self.cat_name = cat_name
        self.cat_url = url
        self.updated = updated

    def haschild(self):
        if self.has_child is None:
            return None
        elif self.has_child is False or self.has_child == 'False':
            self.has_child = False
            return False
        else:
            self.has_child = True
            return True


# Class Categories def
class Categories:
    __categories = None

    def __init__(self):
        self.__categories = dict()

    def __del__(self):
        self.__categories = None

    def is_empty(self):
        if len(self.__categories) == 0:
            return True
        else:
            return False

    def size(self):
        return len(self.__categories)

    def put_cat(self, cat):
        if cat is None:
            return
        self.__categories[cat.cat_id] = cat

    def putall(self, cats):
        if cats is None:
            return
        for cat in cats.get_cats():
            self.__categories[cat.cat_id] = cat

    def get_cat(self, cat_id):
        return self.__categories.get(cat_id)

    def get_cat_ids(self):
        return self.__categories.keys()

    def get_cats(self):
        return self.__categories.values()

    def get_cats_urls(self):
        urls = [] * 0
        for cat in self.get_cats():
            urls.append(cat.cat_url)
        return urls


# Class Product def
class Product:
    prod_id = None
    prod_name = None
    prod_url = None
    prod_cat = None
    prod_desc = None
    prod_feature = None
    prod_img_zoomed_urls = None
    prod_img_main_urls = None
    prod_currency = None
    prod_price = None
    prod_sizes = None
    prod_colors = None
    prod_updated = None

    def __init__(self, prod_id, prod_name, url, cat_id):
        self.prod_id = prod_id
        self.prod_name = prod_name
        self.prod_url = url
        self.prod_cat = cat_id


# Class Products def
class Products:
    __products = None

    def __init__(self):
        self.__products = dict()

    def __del__(self):
        self.__products = None

    def is_empty(self):
        if len(self.__products) == 0:
            return True
        else:
            return False

    def size(self):
        return len(self.__products)

    def put(self, prod):
        if prod is None:
            return
        self.__products[prod.prod_id] = prod

    def putall(self, products):
        if products is None:
            return
        for product in products.get_products():
            self.__products[product.prod_id] = product

    def get(self, prod_id):
        return self.__products.get(prod_id)

    def get_ids(self):
        return self.__products.keys()

    def get_products(self):
        return self.__products.values()

    def get_urls(self):
        urls = [] * 0
        for prod in self.get_products():
            urls.append(prod.prod_url)
        return urls
